#!/usr/bin/python3
#coding=utf-8
import os


#读取文件列表
f=open('etc/list')
clist=[]
for line in f:
	if len(line.strip('\n').strip('\r'))>0:
		clist.append(line.strip('\n').strip('\r'))


#生成文档
docCommand='java -jar lib/jsdoc/jsrun.jar lib/jsdoc/app/run.js \
-a -v -p -t=lib/jsdoc/templates/CodeView -D="title:Castle API" -D="noGlobal:true" -d=doc -o=log/doc.log'
for line in clist:
	docCommand+=' src/'+line+'.js'
print('生成文档中...')
res=os.system(docCommand)
if res>0:
	print('生成文档失败')
	quit(2)
print('生成文档成功')


#压缩.js文件
comCommand='java -jar lib/closure/compiler.jar \
--js_output_file out/core.js \
--compilation_level SIMPLE_OPTIMIZATIONS \
--language_in ECMASCRIPT5 --js'
for line in clist:
	comCommand+=' src/'+line+'.js'
print ('代码压缩中...')
res=os.system(comCommand)
if res>0:
	print('代码压缩失败')
	quit(3)
print ('代码压缩成功')
